package com.wowangz.cms.systemmanage.userduty.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wowangz.cms.common.utils.SysConstant;
import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.systemmanage.duty.pojo.Duty;
import com.wowangz.cms.systemmanage.userduty.dto.UserDutyCheckDto;
import com.wowangz.cms.systemmanage.userduty.dto.UserDutyDto;
import com.wowangz.cms.systemmanage.userduty.pojo.UserDuty;

public class UserDutyService extends BaseService{

	/**
	 * 查询记录的总数
	 * @author HUANGYUAN
	 * @时间 2015年8月5日 下午4:14:14
	 * @param map
	 * @return
	 * @throws ServiceException
	 * @描述
	 */
	public Long queryUserCountByMap(Map<String, Object> map) throws ServiceException{
		return this.getSqlSession().selectOne("userDuty.queryUserCountByMap", map);
	}
	
	/**
	 * @author HUANGYUAN
	 * @时间 2015年8月5日 下午4:14:00
	 * @param map
	 * @return
	 * @throws ServiceException
	 * @描述 查询职责列表
	 */
	public List<UserDutyDto> queryUserPageByMap(Map<String, Object> map) throws ServiceException{
		return this.getSqlSession().selectList("userDuty.queryUserPageByMap", map);
		
	}
	
	public List<UserDuty> queryUserPostByUserid(Long userid) throws ServiceException{
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("userid", userid);
		map.put("statusid", (int)SysConstant.RecordStatus.VALID);
		return this.getSqlSession().selectList("userDuty.queryUserPostByUserid", map);
	}
	
	/**
	 * 查询职责
	 * @param paramMap
	 * @return
	 */
	public List<Duty> queryDutyListByMap(Map<String, Object> paramMap) throws ServiceException{
		List<Duty> list = this.getSqlSession().selectList("userDuty.queryDutyListByMap", paramMap);
		return list;
	}
	
	public void delete(Long userid) throws ServiceException{
		List<UserDuty> list = queryUserPostByUserid(userid);
		if (list != null && list.size() > 0) {
			for (UserDuty userDuty : list) {
				userDuty.setStatusid(SysConstant.RecordStatus.INVALID);
				this.getSqlSession().delete("userDuty.deleteUserPost", userDuty);
			}
		}
	}
	
	public void insert(UserDuty userDuty) throws ServiceException {
		this.getSqlSession().insert("userDuty.insert", userDuty);
	}
	
	public void update(UserDuty userDuty){
		this.getSqlSession().update("userDuty.updateUserDuty", userDuty);
	}
	
	/*

	public List<UserDuty> findByMap(Map<String, Object> paramMap) throws ServiceException{
		return this.getSqlSession().selectList("userDuty.findByMap", paramMap);
	}*/

	
	
	/*
	
	
	
	public UserDuty findUserDutyById(Long id) throws ServiceException{
		return this.getSqlSession().selectOne("userDuty.findUserDutyById", id);
	}
	
	*/
	
	/*public void deleteUserPost(UserDuty userDuty) throws ServiceException{
		this.getSqlSession().update("userDuty.deleteUserPost", userDuty);
	}
	
	*/
	
	
	/**
	 * 分页查询复核总条数
	 * 
	 */
	public long findResultCount(HashMap<String, Object> map) throws Exception {
		Long countNum = this.getSqlSession().selectOne("userDuty.queryCheckListCount", map);
		return countNum;
	}

	/**
	 * 查询复核记录集合
	 * 
	 */
	public List<UserDutyCheckDto> findResultList(HashMap<String, Object> map) throws Exception {
		List<UserDutyCheckDto> list = this.getSqlSession().selectList("userDuty.findCheckListPage", map);
		return list;
	}
	
	/**
	 * 分页查询职责复核总条数
	 * 
	 */
	public long findDutyResultCount(HashMap<String, Object> map) throws Exception {
		Long countNum = this.getSqlSession().selectOne("userDuty.queryDutyCheckListCount", map);
		return countNum;
	}

	/**
	 * 查询职责复核记录集合
	 * 
	 */
	public List<Duty> findDutyResultList(HashMap<String, Object> map) throws Exception {
		List<Duty> list = this.getSqlSession().selectList("userDuty.findDutyCheckListPage", map);
		return list;
	}
	
	/**
	 * 根据ID查询UserDuty
	 *
	 */
	/*public UserDuty findOne(Long id) throws Exception {
		UserDuty userDuty = this.getSqlSession().selectOne("userDuty.findOne", id);
		return userDuty;
	}*/
	
	/**
	 * 根据userid查询UserDuty集合
	 * 
	 */
	/*public List<UserDuty> findByUserid(Long userid) throws Exception {
		List<UserDuty> list = this.getSqlSession().selectList("userDuty.findByUserid", userid);
		return list;
	}*/
	
}
